<template>
  <ych-modal
    :fullscreen="true"
    :title="title"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    :cancelText="$t('m.common.button.close')">

    <a-spin :spinning="confirmLoading">
      <a-tabs defaultActiveKey="1" @change="handleChangeTabs">
        <a-tab-pane :tab="$t('m.system.user.other.basic_info')" key="1" :forceRender="true">
          <a-form :form="form">
            <a-row>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.username')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="" v-decorator.trim="[ 'username', validatorRules.username]"
                           :readOnly="!!model.id"/>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.realname')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="" v-decorator.trim="[ 'realname', validatorRules.realname]"/>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <template v-if="!model.id">
                  <a-form-item :label="$t('m.system.user.entity.password')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input type="password" placeholder=""
                             v-decorator="[ 'password', validatorRules.password]"/>
                  </a-form-item>

                </template>
              </a-col>
              <a-col :span="12">
                <template v-if="!model.id">
                  <a-form-item :label="$t('m.system.user.entity.confirmpassword')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input type="password" @blur="handleConfirmBlur" placeholder=""
                             v-decorator="[ 'confirmpassword', validatorRules.confirmpassword]"/>
                  </a-form-item>
                </template>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <!--部门分配-->
                <a-form-item :label="$t('m.system.user.entity.majarDepName')" :labelCol="labelCol" :wrapperCol="wrapperCol" v-show="!departDisabled">
                  <a-input-search
                    placeholder=""
                    v-model="majarDepName"
                    ref="search"
                    @search="onSearch('majarDepName')">
                    <a-button slot="enterButton" icon="search">{{ $t('m.common.button.select') }}</a-button>
                  </a-input-search>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.workNo')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="" v-decorator.trim="[ 'workNo', validatorRules.workNo]"/>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.selectedRole')" :labelCol="labelCol" :wrapperCol="wrapperCol" v-show="!roleDisabled">
                  <a-select
                    mode="multiple"
                    style="width: 100%"
                    placeholder=""
                    optionFilterProp="children"
                    v-model="selectedRole"
                    :getPopupContainer="(target) => target.parentNode">
                    <a-select-option v-for="(role,roleindex) in roleList" :key="roleindex.toString()" :value="role.id">
                      {{ role.roleName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.selectedJob')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select
                    mode="multiple"
                    style="width: 100%"
                    placeholder=""
                    optionFilterProp="children"
                    v-model="selectedJob">
                    <a-select-option v-for="(sysjob,jobindex) in jobList" :key="jobindex.toString()" :value="sysjob.id">
                      {{ sysjob.jobName }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-row>
                  <!--<a-col :span="24">
                    <a-form-item label="用户编码" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                      <a-input placeholder="请输入用户编码" v-decorator="[ 'userNum', validatorRules.userNum]" />
                    </a-form-item>
                  </a-col>-->
                  <a-col :span="24">
                    <a-form-item :label="$t('m.system.user.entity.userOrder')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                      <a-input-number :min="0" :max="999999999" v-decorator="[ 'userOrder',{'initialValue':0}]"/>
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="24">
                    <a-form-item :label="$t('m.system.user.entity.userSecret')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                      <a-input placeholder="" v-decorator="[ 'userSecret', validatorRules.userSecret]"/>
                    </a-form-item>
                  </a-col>
                </a-row>

              </a-col>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.avatar')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <ych-image-upload class="avatar-uploader" :text="$t('m.common.button.upload')" v-model="fileList"></ych-image-upload>
                </a-form-item>
              </a-col>
            </a-row>
            <!--<a-row>
              <a-col :span="12">
                <a-form-item label="微信号" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                  <a-input placeholder="" v-decorator="[ 'userWeixin', validatorRules.userWeixin]" />
                </a-form-item>
              </a-col>
            </a-row>-->
            <a-row>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.userQq')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="" v-decorator="[ 'userQq', validatorRules.userQq]"/>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.birthday')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-date-picker
                    style="width: 100%"
                    placeholder=""
                    v-decorator="['birthday', {initialValue:!model.birthday?null:moment(model.birthday,dateFormat)}]"
                    :getCalendarContainer="node => node.parentNode"/>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.sex')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select v-decorator="[ 'sex', {}]" placeholder=""
                            :getPopupContainer="(target) => target.parentNode">
                    <a-select-option :value="1">{{$t('m.system.user.other.sex_male')}}</a-select-option>
                    <a-select-option :value="2">{{$t('m.system.user.other.sex_female')}}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.email')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="" v-decorator="[ 'email', validatorRules.email]"/>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.phone')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="" :disabled="isDisabledAuth('user:form:phone')"
                           v-decorator="[ 'phone', validatorRules.phone]"/>
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.telephone')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="" v-decorator="[ 'telephone', validatorRules.telephone]"/>
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-form-item :label="$t('m.system.user.entity.isRealUser')" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <ych-dict-select-tag v-decorator="['isRealUser', {}]" placeholder="" :type="'radio'"
                                       :triggerChange="true" dictCode="is_real_user"/>
                </a-form-item>
              </a-col>
            </a-row>
            <!--<a-row>
              <a-col :span="12">
                <a-form-item label="扩展属性1" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                  <a-input placeholder="请输入扩展属性" v-decorator="[ 'userExt1', validatorRules.userExt1]" />
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item label="扩展属性2" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                  <a-input placeholder="请输入扩展属性" v-decorator="[ 'userExt2', validatorRules.userExt2]" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-form-item label="扩展属性3" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                  <a-input placeholder="请输入扩展属性" v-decorator="[ 'userExt3', validatorRules.userExt3]" />
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item label="扩展属性4" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                  <a-input placeholder="请输入扩展属性" v-decorator="[ 'userExt4', validatorRules.userExt4]" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-form-item label="扩展属性5" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                  <a-input placeholder="请输入扩展属性" v-decorator="[ 'userExt5', validatorRules.userExt5]" />
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item label="扩展属性6" :labelCol="labelCol" :wrapperCol="wrapperCol" >
                  <a-input placeholder="请输入扩展属性" v-decorator="[ 'userExt6', validatorRules.userExt6]" />
                </a-form-item>
              </a-col>
            </a-row>-->


          </a-form>
        </a-tab-pane>
        <a-tab-pane :tab="$t('m.system.user.other.ext_info')" key="2" :forceRender="true">
          <!-- 操作按钮区域 -->
          <div class="table-operator" style="border-top: 5px">
            <a-button @click="addDeptPosition" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
          </div>
          <a-table
            ref="table"
            bordered
            size="middle"
            rowKey="depId"
            :columns="columns"
            :dataSource="minorDeps"
            :pagination="pagination"
          >

            <span slot="action" slot-scope="text, record">
              <a-popconfirm :title="$t('m.common.tip.delete_confirm')" @confirm="() => deleteUserDept(record)">
                      <a>{{ $t('m.common.button.delete') }}</a>
              </a-popconfirm>
            </span>
          </a-table>
        </a-tab-pane>
      </a-tabs>
    </a-spin>
    <depart-window ref="departWindow" @ok="modalFormOk"></depart-window>

  </ych-modal>
</template>

<script>

import moment from 'moment'
// 引入搜索部门弹出框的组件
import departWindow from './DepartWindow'
import { addUser, editUser, queryall, queryAllJob, queryUserRelation } from '@/api/api'
import { disabledAuthFilter } from '@/utils/authFilter'
import { duplicateCheck } from '@/api/api'
import YchImageUpload from '../../../components/ych/YchImageUpload'
import YchConstant from '@/api/YchConstant'
import TokenStorageUtil from "../../../utils/TokenStorageUtil";

export default {
  name: 'UserModal',
  props: {
    portal: {
      type: String,
      default: '0'
    }
  },
  components: {
    YchImageUpload,
    departWindow
  },
  data() {
    return {
      pagination: {},
      departDisabled: false, //是否是我的部门调用该页面
      roleDisabled: false, //是否是角色维护调用该页面
      modalWidth: 800,
      drawerWidth: 700,
      modaltoggleFlag: true,
      confirmDirty: false,
      majarDepName: '', // 保存部门的名称 =>title
      userId: '', //保存用户id
      disableSubmit: false,
      userDepModel: { userId: '', depList: [] }, // 保存SysUserDepart的用户部门中间表数据需要的对象
      majarDep: { depId: '', depName: '', positionId: '', positionName: '', isMajorDep: '' }, //主部门定义，一个
      minorDeps: [], //兼职部门定义，多个
      userJobs: [], //岗位定义，多个
      userRoles: [],//角色定义，多个

      dateFormat: 'YYYY-MM-DD',
      validatorRules: {
        username: {
          rules: [{
            required: true, message:this.$t('m.system.user.verify.username')
          }, {
            validator: this.validateUsername
          }]
        },
        password: {
          rules: [{
            required: true,
            pattern: /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,./]).{8,}$/,
            message: this.$t('m.system.user.verify.password')
          }, {
            validator: this.validateToNextPassword
          }]
        },
        confirmpassword: {
          rules: [{
            required: true, message: this.$t('m.system.user.verify.confirmpassword')
          }, {
            validator: this.compareToFirstPassword
          }]
        },
        realname: { rules: [{ required: true, message: this.$t('m.system.user.verify.realname') }] },
        phone: { rules: [{ validator: this.validatePhone }] },
        email: {
          rules: [{
            validator: this.validateEmail
          }]
        },
        roles: {},
        //  sex:{initialValue:((!this.model.sex)?"": (this.model.sex+""))}
        workNo: {
          rules: [
            { required: true, message: this.$t('m.system.user.verify.workNo') },
            { validator: this.validateWorkNo }
          ]
        },
        telephone: {
          rules: [
            { pattern: /^0\d{2,3}-[1-9]\d{6,7}$/, message: this.$t('m.system.user.verify.telephone') }
          ]
        }
      },
      title: this.$t('m.common.label.operate'),
      visible: false,
      model: {},
      roleList: [],
      jobList: [],
      selectedRole: [],
      selectedJob: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      uploadLoading: false,
      confirmLoading: false,
      headers: {},
      form: this.$form.createForm(this),
      picUrl: '',
      url: {
        fileUpload: bootConfig[process.env.NODE_ENV].VUE_APP_API + YchConstant.PREFIX_SYSTEM + '/common/upload',
        userId: YchConstant.PREFIX_SYSTEM + '/user/generateUserId' // 引入生成添加用户情况下的url
      },
      identity: '1',
      fileList: [],
      columns: [
        {
          title: this.$t('m.system.org.entity.depName'),
          align: 'center',
          width: 180,
          dataIndex: 'depName'
        },
        {
          title: this.$t('m.system.position.entity.positionName'),
          align: 'center',
          width: 180,
          dataIndex: 'positionName'
        },
        {
          title: this.$t('m.common.label.operate'),
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          width: 170
        }
      ]
    }
  },
  created() {
    const token = TokenStorageUtil.get()
    this.headers = { 'X-Access-Token': token }

  },
  computed: {
    uploadAction: function() {
      return this.url.fileUpload
    }
  },
  methods: {
    deleteUserDept(record) {
      let newArr = []
      let newArr1 = []
      this.minorDeps.forEach((item, index, array) => {
        if (!(record.depId == item.depId)) {
          newArr.push(item)
        }
      })
      this.userDepModel.depList.forEach((item, index, array) => {
        if (!(record.depId == item.depId)) {
          newArr1.push(item)
        }
      })
      this.minorDeps = newArr
      this.userDepModel.depList = newArr1
    },
    addDeptPosition() {
      this.$refs.departWindow.add(this.userId,null,null, 'addDeptPosition')
    },
    handleChangeTabs(key) {

    },
    isDisabledAuth(code) {
      return disabledAuthFilter(code)
    },
    //窗口最大化切换
    toggleScreen() {
      if (this.modaltoggleFlag) {
        this.modalWidth = window.innerWidth
      } else {
        this.modalWidth = 800
      }
      this.modaltoggleFlag = !this.modaltoggleFlag
    },
    initialRoleList() {
      queryall().then((res) => {
        if (res.success) {
          this.roleList = res.result
          if (this.portal == '1') {
            this.roleList = this.roleList.filter(vo => vo.back == '0')
          }
        } else {
          //console.log(res.message)
        }
      })
    },
    initialJobList() {
      queryAllJob().then((res) => {
        if (res.success) {
          this.jobList = res.result
        } else {
          //console.log(res.message)
        }
      })
    },
    //加载用户关系信息，包括部门、角色、岗位
    loadUserRelation(userid) {
      queryUserRelation({ userid: userid }).then((res) => {
        if (res.success) {
          if(res.result.userRoleList){
            res.result.userRoleList.map((val, index, arr) => {
              this.userRoles.push(val)
              this.selectedRole.push(val.roleId)
            })
          }

          if(res.result.userJobList){
            res.result.userJobList.map((val, index, arr) => {
              this.userJobs.push(val)
              this.selectedJob.push(val.jobId)
            })
          }

          let minorDepNameNum = 0
          if(res.result.userDepartList){
            res.result.userDepartList.map((val, index, arr) => {
              if (val.isMajorDep == '1') {
                this.majarDep = val
                this.majarDepName = val.depName + (val.positionName ? ('/' + val.positionName) : "")
                this.userDepModel.depList.push(val)
              } else {
                minorDepNameNum++
                this.minorDeps.push(val)
                this.userDepModel.depList.push(val)
                this['minorDepName' + minorDepNameNum] = val.depName + (val.positionName ? ('/' + val.positionName) : "")
              }
            })
          }

        } else {
          //console.log(res.message)
        }
      })
    },

    refresh() {
      this.majarDepName = ''
      this.userId = ''
    },
    add() {
      this.picUrl = ''
      this.refresh()
      this.edit({ isRealUser: '1' })
    },
    edit(record) {
      this.resetScreenSize() // 调用此方法,根据屏幕宽度自适应调整抽屉的宽度
      this.initialRoleList()
      this.initialJobList()
      this.majarDepName = ''
      this.form.resetFields()
      if (record.hasOwnProperty('id')) {
        this.loadUserRelation(record.id)
        this.picUrl = 'Has no pic url yet'
      }
      this.fileList = record.avatar
      this.userId = record.id
      this.visible = true
      this.model = Object.assign({}, record)
      this.$nextTick(() => {
        this.form.setFieldsValue(this.lodash.pick(this.model, 'username', 'sex', 'realname', 'workNo', 'userSecret', 'userOrder', 'isRealUser', 'userQq', 'email', 'userExt1', 'userExt2', 'userExt3', 'userExt4', 'userExt5', 'userExt6', 'phone'))
      })
    },

    close() {
      this.$emit('close')
      this.visible = false
      this.disableSubmit = false
      this.selectedRole = []
      this.selectedJob = []
      this.userDepModel = { userId: '', depList: [] }
      this.majarDepName = ''
      this.majarDep = { depId: '', depName: '', positionId: '', positionName: '', isMajorDep: '' } //主部门定义，一个
      this.minorDeps = [] //兼职部门定义，多个
      this.userJobs = [] //岗位定义，多个
      this.userRoles = []//角色定义，多个
    },
    moment,
    handleSubmit() {

      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          if (!values.birthday) {
            values.birthday = ''
          } else {
            values.birthday = values.birthday.format(this.dateFormat)
          }
          let formData = Object.assign(this.model, values)
          if (that.fileList != '') {
            formData.avatar = that.fileList
          } else {
            formData.avatar = null
          }
          formData.selectedroles = this.selectedRole.length > 0 ? this.selectedRole.join(',') : ''
          formData.selectedjobs = this.selectedJob.length > 0 ? this.selectedJob.join(',') : ''
          formData.selecteddeparts = JSON.stringify(this.userDepModel.depList)
          //console.log(formData, 'formData')
          let obj
          if (!this.model.id) {
            formData.id = this.userId
            obj = addUser(formData)
          } else {
            obj = editUser(formData)
          }
          obj.then((res) => {
            if (res.success) {
              that.messageUtil.success(res.message)
              that.$emit('ok')
            } else {
              that.messageUtil.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })

        }
      })
    },
    handleCancel() {
      this.close()
    },
    validateToNextPassword(rule, value, callback) {
      const form = this.form
      const confirmpassword = form.getFieldValue('confirmpassword')

      if (value && confirmpassword && value !== confirmpassword) {
        callback(this.$t('m.system.user.verify.diffpassword'))
      }
      if (value && this.confirmDirty) {
        form.validateFields(['confirm'], { force: true })
      }
      callback()
    },
    compareToFirstPassword(rule, value, callback) {
      const form = this.form
      if (value && value !== form.getFieldValue('password')) {
        callback(this.$t('m.system.user.verify.diffpassword'))
      } else {
        callback()
      }
    },
    validatePhone(rule, value, callback) {
      if (!value) {
        callback()
      } else {
        if (new RegExp(/^1[3|4|5|7|8|9][0-9]\d{8}$/).test(value)) {

          var params = {
            tableName: 'sys_user',
            fieldName: 'phone',
            fieldVal: value,
            dataId: this.userId
          }
          duplicateCheck(params).then((res) => {
            if (res.success) {
              callback()
            } else {
              callback(this.$t('m.system.user.verify.phoneexist'))
            }
          })
        } else {
          callback(this.$t('m.system.user.verify.phoneformat'))
        }
      }
    },
    validateEmail(rule, value, callback) {
      if (!value) {
        callback()
      } else {
        if (new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(value)) {
          var params = {
            tableName: 'sys_user',
            fieldName: 'email',
            fieldVal: value,
            dataId: this.userId
          }
          duplicateCheck(params).then((res) => {
            //console.log(res)
            if (res.success) {
              callback()
            } else {
              callback(this.$t('m.system.user.verify.emailexist'))
            }
          })
        } else {
          callback(this.$t('m.system.user.verify.emailformat'))
        }
      }
    },
    validateUsername(rule, value, callback) {
      var params = {
        tableName: 'sys_user',
        fieldName: 'username',
        fieldVal: value,
        dataId: this.userId
      }
      duplicateCheck(params).then((res) => {
        if (res.success) {
          callback()
        } else {
          callback(this.$t('m.system.user.verify.userexist'))
        }
      })
    },
    validateWorkNo(rule, value, callback) {
      var params = {
        tableName: 'sys_user',
        fieldName: 'work_no',
        fieldVal: value,
        dataId: this.userId
      }
      duplicateCheck(params).then((res) => {
        if (res.success) {
          callback()
        } else {
          callback(this.$t('m.system.user.verify.workNoexist'))
        }
      })
    },
    handleConfirmBlur(e) {
      const value = e.target.value
      this.confirmDirty = this.confirmDirty || !!value
    },
    normFile(e) {
      //console.log('Upload event:', e)
      if (Array.isArray(e)) {
        return e
      }
      return e && e.fileList
    },
    beforeUpload: function(file) {
      var fileType = file.type
      if (fileType.indexOf('image') < 0) {
        this.messageUtil.warning(this.$t('m.common.tip.pic_warn'))
        return false
      }
      //TODO 验证文件大小
    },
    handleChange(info) {
      this.picUrl = ''
      if (info.file.status === 'uploading') {
        this.uploadLoading = true
        return
      }
      if (info.file.status === 'done') {
        var response = info.file.response
        this.uploadLoading = false
        //console.log(response)
        if (response.success) {
          this.model.avatar = response.message
          this.picUrl = 'Has no pic url yet'
        } else {
          this.messageUtil.warning(response.message)
        }
      }
    },
    // 搜索用户对应的部门API
    onSearch(modelName) {
      this.$refs.departWindow.add(this.userId, this.majarDep.depId,this.majarDep.positionId,modelName)
    },
    // 获取用户对应部门弹出框提交给返回的数据
    modalFormOk(formData) {
      this.userId = formData.userId
      this.userDepModel.userId = formData.userId
      let modelName = formData.modelName
      let _depId = formData.departIdList[0].depId
      let _depName = formData.departIdList[0].depName
      let _positionId = formData.positionList.length > 0 ? formData.positionList[0].id : ''
      let _positionName = formData.positionList.length > 0 ? formData.positionList[0].positionName : ''
      if (modelName == 'majarDepName') { //主部门
        let jzDeptList = this.userDepModel.depList.filter(item => item.isMajorDep != '1')
        let isExist = false
        jzDeptList.forEach((item, index, array) => {
          if (_depId == item.depId) {
            isExist = true
          }
        })
        if (isExist) {
          this.messageUtil.warning(this.$t('m.system.user.verify.deptexist'))
          return
        }
        this.majarDep = {
          depId: _depId,
          depName: _depName,
          positionId: _positionId,
          positionName: _positionName,
          isMajorDep: '1'
        }
        this.majarDepName = _depName + (_positionName ? ('/' + _positionName) : '')
        this.userDepModel.depList = jzDeptList
        this.userDepModel.depList.push(this.majarDep)
      } else if (modelName == 'addDeptPosition') {
        let isExist = false
        this.userDepModel.depList.forEach((item, index, array) => {
          if (_depId == item.depId) {
            isExist = true
          }
        })
        if (isExist) {
          this.messageUtil.warning(this.$t('m.system.user.verify.deptexist'))
          return
        }
        let deptPosition = {
          depId: _depId,
          depName: _depName,
          positionId: _positionId,
          positionName: _positionName,
          isMajorDep: '0'
        }
        this.minorDeps.push(deptPosition)
        this.userDepModel.depList.push(deptPosition)
      }
    },
    // 根据屏幕变化,设置抽屉尺寸
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      if (screenWidth < 500) {
        this.drawerWidth = screenWidth
      } else {
        this.drawerWidth = 700
      }
    }
  }
}
</script>

<style lang="less" scoped>
.avatar-uploader > .ant-upload {
  width: 104px;
  height: 104px;
}

.ant-upload-select-picture-card i {
  font-size: 49px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}

.ant-table-tbody .ant-table-row td {
  padding-top: 10px;
  padding-bottom: 10px;
}
</style>
